R Markdown

<<<<<<< HEAD
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5     ✓ purrr   0.3.4
## ✓ tibble  3.1.5     ✓ dplyr   1.0.7
=======
rm(list=ls())
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5     ✓ purrr   0.3.4
## ✓ tibble  3.1.2     ✓ dplyr   1.0.7
>>>>>>> b0db76007b39124248792c541400c66511261655
## ✓ tidyr   1.1.4     ✓ stringr 1.4.0
## ✓ readr   1.4.0     ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
<<<<<<< HEAD =======
setwd("~/Documents/GitHub/Assignment-1")


pge_data <- read_csv("https://pge-energydatarequest.com/public_datasets")
>>>>>>> b0db76007b39124248792c541400c66511261655
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   `<noscript><meta http-equiv='refresh' content='0;url=https://pge-energydatarequest.com/nojswarn'></noscript><!DOCTYPE html>` = col_character()
## )
## Warning: 1279 parsing failures.
## row col           expected actual                                                file
## 104  -- delimiter or quote      : 'https://pge-energydatarequest.com/public_datasets'
## 104  -- delimiter or quote      a 'https://pge-energydatarequest.com/public_datasets'
## 104  -- delimiter or quote      : 'https://pge-energydatarequest.com/public_datasets'
## 104  -- delimiter or quote      t 'https://pge-energydatarequest.com/public_datasets'
## 104  -- delimiter or quote      : 'https://pge-energydatarequest.com/public_datasets'
## ... ... .................. ...... ...................................................
## See problems(...) for more details.
<<<<<<< HEAD =======
pge_20_q1_elec <- read_csv("PGE_2020_Q1_ElectricUsageByZip.csv")
>>>>>>> b0db76007b39124248792c541400c66511261655
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALKWH = col_number(),
##   AVERAGEKWH = col_number()
## )
<<<<<<< HEAD =======
library(tidyverse)

years <- 2017:2020
quarters <- 1:4
type <- "Electric"

pge_1720_elec <- NULL
for(year in years) {
  for(quarter in quarters) {
  
  filename <- 
    paste0(
      "PGE_",
      year,
      "_Q",
      quarter,
      "_",
      type,
      "UsageByZip.csv"
    )
  print(filename)
  
  temp <- read_csv(filename)
  
  pge_1720_elec <- rbind(pge_1720_elec,temp)
  # 

  saveRDS(pge_1720_elec, "pge_1720_elec.rds")
  }
}
>>>>>>> b0db76007b39124248792c541400c66511261655
## [1] "PGE_2017_Q1_ElectricUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALKWH = col_number(),
##   AVERAGEKWH = col_number()
## )
## [1] "PGE_2017_Q2_ElectricUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALKWH = col_number(),
##   AVERAGEKWH = col_number()
## )
## [1] "PGE_2017_Q3_ElectricUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALKWH = col_number(),
##   AVERAGEKWH = col_number()
## )
## [1] "PGE_2017_Q4_ElectricUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALKWH = col_number(),
##   AVERAGEKWH = col_number()
## )
## [1] "PGE_2018_Q1_ElectricUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALKWH = col_number(),
##   AVERAGEKWH = col_number()
## )
## [1] "PGE_2018_Q2_ElectricUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALKWH = col_number(),
##   AVERAGEKWH = col_number()
## )
## [1] "PGE_2018_Q3_ElectricUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALKWH = col_number(),
##   AVERAGEKWH = col_number()
## )
## [1] "PGE_2018_Q4_ElectricUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALKWH = col_number(),
##   AVERAGEKWH = col_number()
## )
## [1] "PGE_2019_Q1_ElectricUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALKWH = col_number(),
##   AVERAGEKWH = col_number()
## )
## [1] "PGE_2019_Q2_ElectricUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALKWH = col_number(),
##   AVERAGEKWH = col_number()
## )
## [1] "PGE_2019_Q3_ElectricUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALKWH = col_number(),
##   AVERAGEKWH = col_number()
## )
## [1] "PGE_2019_Q4_ElectricUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALKWH = col_number(),
##   AVERAGEKWH = col_number()
## )
## [1] "PGE_2020_Q1_ElectricUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALKWH = col_number(),
##   AVERAGEKWH = col_number()
## )
## [1] "PGE_2020_Q2_ElectricUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALKWH = col_number(),
##   AVERAGEKWH = col_number()
## )
## [1] "PGE_2020_Q3_ElectricUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALKWH = col_number(),
##   AVERAGEKWH = col_number()
## )
## [1] "PGE_2020_Q4_ElectricUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALKWH = col_number(),
##   AVERAGEKWH = col_number()
## )
<<<<<<< HEAD
## [1] "numeric"
=======
class(pge_1720_elec$TOTALKWH)
## [1] "numeric"
# adding 2021 Q1 and Q2
year <- 2021
quarters <- 1:2
type <- "Electric"

pge_21_electric <- NULL
  for(quarter in quarters) {
  filename <- 
    paste0(
      "PGE_",
      year,
      "_Q",
      quarter,
      "_",
      type,
      "UsageByZip.csv"
    )
  print(filename)
  
  temp <- read_csv(filename)
  
  pge_21_electric <- rbind(pge_21_electric,temp)
  # 

  saveRDS(pge_21_electric, "pge_21_electric.rds")
}
>>>>>>> b0db76007b39124248792c541400c66511261655
## [1] "PGE_2021_Q1_ElectricUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALKWH = col_number(),
##   AVERAGEKWH = col_number()
## )
## [1] "PGE_2021_Q2_ElectricUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALKWH = col_number(),
##   AVERAGEKWH = col_number()
## )
<<<<<<< HEAD
## [1] "numeric"
## [1] "numeric"
## [1] "numeric"
=======
class(pge_21_electric$TOTALKWH)
## [1] "numeric"
class(pge_1720_elec$TOTALKWH)
## [1] "numeric"
pge_elec_total <- rbind(pge_1720_elec, pge_21_electric)

class(pge_elec_total$TOTALKWH)
## [1] "numeric"
library(tidyverse)

years <- 2017:2020
quarters <- 1:4
type <- "Gas"

pge_1720_gas <- NULL
for(year in years) {
  for(quarter in quarters) {
  filename <- 
    paste0(
      "PGE_",
      year,
      "_Q",
      quarter,
      "_",
      type,
      "UsageByZip.csv"
    )
  print(filename)
  
  temp <- read_csv(filename)
  
  pge_1720_gas <- rbind(pge_1720_gas,temp)
  # 

  saveRDS(pge_1720_gas, "pge_1720_gas.rds")
  }
}
>>>>>>> b0db76007b39124248792c541400c66511261655
## [1] "PGE_2017_Q1_GasUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALTHM = col_number(),
##   AVERAGETHM = col_number()
## )
## [1] "PGE_2017_Q2_GasUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALTHM = col_number(),
##   AVERAGETHM = col_number()
## )
## [1] "PGE_2017_Q3_GasUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALTHM = col_number(),
##   AVERAGETHM = col_double()
## )
## [1] "PGE_2017_Q4_GasUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALTHM = col_number(),
##   AVERAGETHM = col_number()
## )
## [1] "PGE_2018_Q1_GasUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALTHM = col_number(),
##   AVERAGETHM = col_number()
## )
## [1] "PGE_2018_Q2_GasUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALTHM = col_number(),
##   AVERAGETHM = col_number()
## )
## [1] "PGE_2018_Q3_GasUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALTHM = col_number(),
##   AVERAGETHM = col_double()
## )
## [1] "PGE_2018_Q4_GasUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALTHM = col_number(),
##   AVERAGETHM = col_number()
## )
## [1] "PGE_2019_Q1_GasUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALTHM = col_number(),
##   AVERAGETHM = col_number()
## )
## [1] "PGE_2019_Q2_GasUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALTHM = col_number(),
##   AVERAGETHM = col_number()
## )
## [1] "PGE_2019_Q3_GasUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALTHM = col_number(),
##   AVERAGETHM = col_number()
## )
## [1] "PGE_2019_Q4_GasUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALTHM = col_number(),
##   AVERAGETHM = col_number()
## )
## [1] "PGE_2020_Q1_GasUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALTHM = col_number(),
##   AVERAGETHM = col_number()
## )
## [1] "PGE_2020_Q2_GasUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALTHM = col_number(),
##   AVERAGETHM = col_number()
## )
## [1] "PGE_2020_Q3_GasUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALTHM = col_number(),
##   AVERAGETHM = col_double()
## )
## [1] "PGE_2020_Q4_GasUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALTHM = col_number(),
##   AVERAGETHM = col_number()
## )
<<<<<<< HEAD =======
# adding 2021 Q1 and Q2


year <- 2021
quarters <- 1:2
type <- "Gas"

pge_21_gas <- NULL
  for(quarter in quarters) {
  filename <- 
    paste0(
      "PGE_",
      year,
      "_Q",
      quarter,
      "_",
      type,
      "UsageByZip.csv"
    )
  print(filename)
  
  temp <- read_csv(filename)
  
  pge_21_gas <- rbind(pge_21_gas,temp)
  # 

  saveRDS(pge_21_gas, "pge_21_gas.rds")
}
>>>>>>> b0db76007b39124248792c541400c66511261655
## [1] "PGE_2021_Q1_GasUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALTHM = col_number(),
##   AVERAGETHM = col_number()
## )
## [1] "PGE_2021_Q2_GasUsageByZip.csv"
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   ZIPCODE = col_double(),
##   MONTH = col_double(),
##   YEAR = col_double(),
##   CUSTOMERCLASS = col_character(),
##   COMBINED = col_character(),
##   TOTALCUSTOMERS = col_number(),
##   TOTALTHM = col_number(),
##   AVERAGETHM = col_number()
## )
<<<<<<< HEAD
## [1] "numeric"
=======
pge_gas_total <- rbind(pge_1720_gas, pge_21_gas)

class(pge_gas_total$TOTALTHM)
## [1] "numeric"
#Conversions
library(tidyverse)
#KWH to KBTU
pge_elec_total$TOTALKBTU <- pge_elec_total$TOTALKWH *  3.412
#Therms to KBTUs
pge_gas_total$TOTALKBTU <- pge_gas_total$TOTALTHM * 99976.1
#Plots

library(tidyverse)
library(plotly)
>>>>>>> b0db76007b39124248792c541400c66511261655
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
<<<<<<< HEAD
## [1] "Elec- Agricultural" "Elec- Commercial"   "Elec- Industrial"  
## [4] "Elec- Residential"
=======
#Electric 
unique(pge_elec_total$CUSTOMERCLASS)
## [1] "Elec- Agricultural" "Elec- Commercial"   "Elec- Industrial"  
## [4] "Elec- Residential"
res_elec <- pge_elec_total[(pge_elec_total$CUSTOMERCLASS=="Elec- Residential"), na.rm = TRUE]

res_elec$TOTALKWH <- NULL

res_elec$AVERAGEKWH <- NULL

com_elec <- pge_elec_total[which(pge_elec_total$CUSTOMERCLASS=="Elec- Commercial"), na.rm = TRUE]

com_elec$TOTALKWH <- NULL

com_elec$AVERAGEKWH <- NULL

#Gas

res_gas <- pge_gas_total[which(pge_gas_total$CUSTOMERCLASS=="Gas- Residential"), na.rm = TRUE]

res_gas$TOTALTHM <- NULL

res_gas$AVERAGETHM <- NULL

com_gas <- pge_gas_total[which(pge_gas_total$CUSTOMERCLASS=="Gas- Commercial"), na.rm = TRUE]

com_gas$TOTALTHM <- NULL

com_gas$AVERAGETHM <- NULL

#combine

res_data <- rbind(res_elec, res_gas)
  
com_data <- rbind(com_elec, com_gas)
library(tidyverse)
library(plotly)

#Graph 

pge_chart_commercial <-
 com_data %>% 
  ggplot() +
  geom_bar(
    aes(
      x = MONTH,
      y = TOTALKBTU,
      fill = CUSTOMERCLASS
    ),
    stat = "identity",
    position = "stack"
  ) +
  labs(
    x = "Month",
    y = "KBTU",
    title = "PG&E Territory Monthly Commercial Usage",
    fill = "Power Type"
  )

pge_chart_commercial %>% 
  ggplotly() %>% 
  layout(
    xaxis = list(fixedrange = T),
    yaxis = list(fixedrange = T)
  ) %>% 
  config(displayModeBar = F)
library(tidyverse)
library(plotly)

#Residential
plot_ly() %>% 
   add_trace(
    data = res_data %>% filter(CUSTOMERCLASS == "Gas- Residential"),
    x = ~MONTH,
    y = ~TOTALKBTU,
    type = "bar",
    name = "Gas"
  ) %>% 
  add_trace(
    data = res_data %>% filter(CUSTOMERCLASS == "Elec- Residential"),
    x = ~MONTH,
    y = ~TOTALKBTU,
    type = "bar",
    name = "Electric"
  ) %>% 
  layout(
    xaxis = list(
      title = "Month",
      fixedrange = T
    ),
    yaxis = list(
      title = "BTU",
      fixedrange = T
    ),
    barmode = "stack",
    legend = list(title = list(text = "Power Type"))
  ) %>% 
  config(displayModeBar = F)
# Commercial 
library(tidyverse)
library(plotly)


plot_ly() %>% 
   add_trace(
    data = com_data %>% filter(CUSTOMERCLASS == "Gas- Commercial"),
    x = ~MONTH %>% factor(),
    y = ~TOTALKBTU,
    type = "bar",
    name = "Gas"
  ) %>% 
  add_trace(
    data = com_data %>% filter(CUSTOMERCLASS == "Elec- Commercial"),
    x = ~MONTH %>% factor(),
    y = ~TOTALKBTU,
    type = "bar",
    name = "Electric"
  ) %>% 
  layout(
    xaxis = list(
      title = "Month",
      fixedrange = T
    ),
    yaxis = list(
      title = "BTU",
      fixedrange = T
    ),
    barmode = "stack",
    legend = list(title = list(text = "Power Type"))
  ) %>% 
  config(displayModeBar = F)

On the aggregate, although I was not able to delineate year on year patterns visually on this attempt, the PGE electricity and gas usage across the commercial and residential sectors both follow a visible and consistent seasonal trend from 2017-2021, with increases in usage across colder months and seasons and a significant drop with the advent of warmer weather.

I assumed that this seasonality trend would be true across both the residential and commercial data sets.

There is a further assumptions regarding the pandemic that I am leaning on here. That is, Covid may have driven increases in residential electric and gas power usage, and driven decreases in the commercial sector with the mass shift to remote working and reliance on electricity for communication, work, and and increasingly localized home-based working society.

>>>>>>> b0db76007b39124248792c541400c66511261655